import java.util.Arrays;

/**
 * @ Author     ：侯耀祖
 * @ Description：
 */
public class Z {
    public String convert(String s, int numRows) {
        if (numRows == 1) {
            return s;
        }
        StringBuilder[] rows = new StringBuilder[numRows];
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < numRows; i++) {
            rows[i] = new StringBuilder();
        }
        int j = 0, flag = 1;
        for (int i = 0; i < s.length(); i++) {
            rows[j].append(s.charAt(i));
            j+=flag;
            if (j+1 == numRows||j==0) {
                flag = -flag;
            }
        }
        for (int i = 0; i < numRows; i++) {
            result.append(rows[i]);
        }
        return result.toString();
    }
}
